# -*- coding: utf-8 -*-
# @Time : 2021/9/10 13:50
# @Author : 阿怪
# @Email : scg@gmail.com
# @File : CRM-ST-ZNX-16.py
# @Project : crm自动化测试项目实战

'''验证站内信的回复功能—正确输入回复内容'''

from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

driver = webdriver.Chrome()
cookie = {'name': 'PHPSESSID', 'value': '0onrpth7nsd6mbi1hfgi99o2b1'}  # 获取到cookid
driver.get('http://192.168.1.140/')  # 访问服务器
driver.add_cookie(cookie)
driver.get('http://192.168.1.140/crm3/index.php?m=message')
#admin账号进入站内信首页


#1.点击写信进入编辑界面
add_send_locator = (By.ID,'send')
driver.find_element(*add_send_locator).click()
sleep(3)

#2.输入信息啥的
text_locator = (By.NAME,'content')   #内容输入框定位器
submit_locator = (By.NAME,'submit')    #发送按钮定位器

driver.find_element(By.CSS_SELECTOR,'#ta1 > input').click()    #收信人点击全选
driver.find_element(*text_locator).send_keys('我是测试')
driver.find_element(*submit_locator).click()    #发送

#3.去点击刚刚添加的这条信息查看，再点回复
driver.find_element(By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(1) > td:nth-child(2) > a').click()

reply_locator = (By.ID,'reply')
driver.find_element(*reply_locator).click()
sleep(3)
reply_text_locator = (By.NAME,'content')
driver.find_element(*reply_text_locator).send_keys('收到测试信息')   #编辑回复内容
driver.find_element(By.NAME,'submit').click()

#4.断言：在首页获取最新一条自我回复的消息内容，是”收到测试信息“，即通过
text = driver.find_element(By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(1) > td:nth-child(2) > a').text
print(text)

sleep(2)
driver.quit()
